package com.seadragon.app.ksr.model.tiger;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;
import javax.persistence.Table;

import org.hibernate.annotations.Type;

import com.seadragon.app.ksr.model.AddressType;
import com.vividsolutions.jts.geom.MultiPolygon;

@Entity
@Table(name = "STATE", schema = "TIGER")
@NamedNativeQueries({ 
	@NamedNativeQuery(name = "findAdjacentStates", 
			query = "select b.* from tiger.state a inner join tiger.state b on ST_DWithin(a.the_geom, b.the_geom, 0.001) where a.stusps=:stateName", 
			resultClass = State.class)
})
public class State extends Location{
	@Id
	@Column(name = "GID", updatable = false, insertable = false)
	private long id;

	@Column(name = "STATEFP", updatable = false, insertable = false)
	private String geoid;

	@Column(name = "STUSPS", updatable = false, insertable = false)
	private String stusps;

	@Column(name = "NAME", updatable = false, insertable = false)
	private String name;

	@Column(name = "FUNCSTAT", updatable = false, insertable = false)
	private String funcStat;

	@Column(name = "INTPTLAT", updatable = false, insertable = false)
	private String intptlat;
	
	@Column(name = "INTPTLON", updatable = false, insertable = false)
	private String intptlon;
	
	@Column(name = "THE_GEOM", updatable = false, insertable = false)
	@Type(type = "org.hibernate.spatial.GeometryType")
	private MultiPolygon geom;
	
	public State(){}
	
	public State(String stusps){
		this.stusps = stusps;
	}
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getStatefp() {
		return geoid;
	}

	public String getGeoid() {
		return geoid;
	}

	public void setGeoid(String geoid) {
		this.geoid = geoid;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getStusps() {
		return stusps;
	}

	public void setStusps(String stusps) {
		this.stusps = stusps;
	}

	public String getFuncStat() {
		return funcStat;
	}

	public void setFuncStat(String funcStat) {
		this.funcStat = funcStat;
	}

	public MultiPolygon getGeom() {
		return geom;
	}

	public void setGeom(MultiPolygon geom) {
		this.geom = geom;
	}

	@Override
	public AddressType getLocationType() {
		return AddressType.STATE;
	}

	@Override
	public Double getLatitude() {
		return null;
	}

	@Override
	public Double getLongitude() {
		return null;
	}

	@Override
	public String getState() {
		return stusps;
	}

	public void setState(String state) {
		this.stusps = state;
	}
}
